package com.waterworld.watch.chat.manager;

import android.content.Context;

import com.waterworld.watch.chat.interfaces.IChatManager;
import com.waterworld.watch.common.application.MyApplication;
import com.waterworld.watch.common.net.BaseObserverListener;
import com.waterworld.watch.common.net.BaseResultBean;
import com.waterworld.watch.common.net.NetManager;
import com.waterworld.watch.home.manager.HomeManager;
import com.waterworld.watch.login.manager.LoginManager;

import java.io.File;

import rx.Subscriber;

/**
 * Created by nhuan
 * Time:2019/3/14.
 */

public class ChatManager implements IChatManager {

    private static ChatManager mInstance;
    private Context context;

    public static ChatManager getInstance(){
        if(mInstance == null){
            synchronized (ChatManager.class){
                if(mInstance == null){
                    mInstance = new ChatManager(MyApplication.getContext());
                }
            }
        }
        return mInstance;
    }

    private ChatManager(Context context){
        super();
        this.context = context;
    }

    @Override
    public void listGroup(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().listGroup(new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void listManageWatch(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().listManageWatch(new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void listGroupAllowUser(Integer watchId, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().listGroupAllowUser(watchId, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void uploadGroupHead(File file, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().uploadGroupHead(file, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void createGroup(String json, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().createGroup(json, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void deleteGroup(Integer groupId, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().deleteGroup(groupId, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void updateGroupName(Integer groupId, String name, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().updateGroupName(groupId, name, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void listGroupMember(Integer groupId, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().listGroupMember(groupId, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void addGroupMember(String json, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().addGroupMember(json, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void deleteGroupMember(String json, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().deleteGroupMember(json, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void quitGroup(Integer groupId, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().quitGroup(groupId, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void sendGroupMsg(String json, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().sendGroupMsg(json, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void uploadGroupVoice(Integer groupId, File file, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().uploadGroupVoice(groupId, file, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void getGroupMsg(Integer groupId, Integer msgId, Integer pageSize, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().getGroupMsg(groupId, msgId, pageSize, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void listGroupMsg(Integer groupId, Integer msgId, Integer pageNum, Integer pageSize, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().listGroupMsg(groupId, msgId, pageNum, pageSize, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }
}
